<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<head>
</head>
<body>
<article class="page-container" id="mainArt">
	<form id="form1" class="form form-horizontal" action="${ctx}/role/saveEntity.do" method="post" enctype="multipart/form-data">
		<c:if test="${entity.id != null}"><input type="hidden" id="entityID" name="id" value="${entity.id }" /></c:if>
		<div class="row cl">
			<label class="form-label col-xs-2"><span class="c-red">*</span>名称:</label>
			<div class="formControls col-xs-4">
				<input id="name" name="name" class="input-text required" value="${entity.name }"  type="text"  />
			</div>
			<%--<label class="form-label col-xs-2"><span class="c-red">*</span>code:</label>
			<div class="formControls col-xs-4">
				<input id="code" name="code" class="input-text required number"   value="${entity.code }"  type="text"/>
			</div>--%>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-2"><span class="c-red">*</span>描述:</label>
			<div class="formControls col-xs-10">
				<textarea id="remark" name="remark" class="textarea" value="${entity.remark }" placeholder=""   type="text" >${entity.remark }</textarea>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-2"><span class="c-red">*</span>资源:</label>
			<div class="formControls col-xs-10">
				<input type="text" id="resourceInput" class="input-text " value=""  onclick="showMenu('resourceInput',false);" readonly="readonly" >
				<input type="hidden" id="resourceValue" value=""  name="resIds">
				<div  id="menuContent_resourceInput" class="ztree" style="position: absolute;display: none;padding: 0px;">
					<ul id="showResourceTree"  class="ztree"  style="margin-top: 0px; width: 180px; height: 150px; -moz-user-select: none;"></ul>
				</div>
			</div>
		</div>

		<div class="row cl">
			<div id="buttonDiv" class="col-xs-6 col-xs-offset-3 text-c">
				<c:if test="${entity.id != null}">
					<a href="javascript:submit();" class="btn btn-success radius"><i class="Hui-iconfont">&#xe60c;</i> 修改</a>
				</c:if>
				<c:if test="${entity.id == null}">
					<a href="javascript:submit();" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
				</c:if>
			</div>
		</div>
	</form>
</article>
<script type="text/javascript">
	$(function(){
        var setting={
            check: {
                enable: true,
                chkStyle : "checkbox",
                chkboxType: { "Y": "ps", "N": "s" }
            },
            callback: {
                onCheck: zTreeOnCheck
            }
        };
        var roleId = "${entity.id}";
        $.ajax({
            type: 'POST',
            dataType : "json",
            url: "${ctx}/role/getResourceListDateForRole?roleId="+roleId,
            success:function(data){
                $.fn.zTree.init($("#showResourceTree"), setting,data);
                $("#resourceInput").attr("value", getTreeCheckboxNameCheck("showResourceTree"));
                $("#resourceValue").attr("value",getTreeCheckboxIdCheck("showResourceTree"));
            }
        });

        $("#form1").validate({
			rules:{
			},
			onkeyup:false,
			focusCleanup:true,
			success:"valid",
			submitHandler:function(form){
				var index = layer.load();
				$(form).ajaxSubmit({
	                success:function(data){ //提交成功的回调函数  
	            	  	layer.close(index);  
	                    if(data.flag==200){
	    		        	layer.alert(data.msg,{icon:6},function(index){
	                			if(data.isUpdate == "false"){
	                				parent.location.reload();
	                			}else{
	                				parent.reloadTable();
	                			}
    		                	//关闭当前弹窗
    		    				var index = parent.layer.getFrameIndex(window.name);
    		    				parent.$('.btn-refresh').click();
    		    				parent.layer.close(index);
                				layer.close(index);
                			});
	    	       		} else{
	    	       			layer.alert(data.msg, {icon: 5});
	    	       		}
	                },
	                error:function(data){
	            		layer.close(index);  
	                	layer.alert("操作失败",{icon:5},function(index){
            				//刷新父级
            				parent.location.reload();
		                	//关闭当前弹窗
		    				var index = parent.layer.getFrameIndex(window.name);
		    				parent.$('.btn-refresh').click();
		    				parent.layer.close(index);
            				layer.close(index);
            			});     
	                }
				});
			}
		});
	});
	function submit(){
		$("#form1").submit();
	}

    function  zTreeOnCheck(event, treeId, treeNode) {
        $("#resourceInput").attr("value", getTreeCheckboxNameCheck("showResourceTree"));
        $("#resourceValue").attr("value",getTreeCheckboxIdCheck("showResourceTree"));
    };
</script>
</body>
</html>